package com.example.content.activity

import android.content.Intent
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import com.example.content.*
import com.example.content.databinding.ActivityCommonBinding
import com.example.content.fragment.detail.PhotoDetailFragment
import com.example.content.fragment.me.*
import com.example.content.fragment.me.coin.*
import com.example.content.fragment.me.vip.MyVipFragment
import com.example.content.fragment.personal.PersonalFragment

class CommonActivity : BaseUIActivity() {

    lateinit var dataBinding: ActivityCommonBinding
    lateinit var fragment:Fragment

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_common)
        initFragment()
    }

    private fun initFragment() {
        fragment = when (intent.getIntExtra(KEY_FRAGMENT,0)) {
            ME_FOLLOWERS -> {
                FollowersListFragment.newInstance()
            }
            ME_MY_COIN_TYPE -> {
                MyCoinFragment.newInstance()
            }
            ME_VIP_PAGE_TYPE -> {
                MyVipFragment.newInstance()
            }
            ME_EDIT_USER_INFO_TYPE -> {
                UserInfoEditFragment.newInstance()
            }
            PERSONAL_INFO_CENTER -> {
                PersonalFragment.newInstance()
            }
            ME_FEEDBACK_PAGE_TYPE -> {
                FeedBackFragment.newInstance()
            }
            PRODUCT_DETAIL -> {
                PhotoDetailFragment.newInstance()
            }
            ME_CHARGE_COIN_TYPE -> {
                ChargeFragment.newInstance()
            }
            ME_CASH_OUT_TYPE -> {
                CashOutFragment.newInstance()
            }
            ME_CERTIFICATION_TYPE -> {
                CertificationFragment.newInstance()
            }
            ME_PAY_VERIFY_TYPE -> {
                PayVerifyFragment.newInstance()
            }
            ME_SELECT_PAY_CARD_TYPE -> {
                SelectBankCardFragment.newInstance()
            }
            ME_ADD_BANK_CARD_TYPE -> {
                AddBankCardFragment.newInstance()
            }
            ME_FILL_BANK_INFO_TYPE -> {
                FillBankInfoFragment.newInstance()
            }
            SHARE_PERSONAL_CARD_TYPE -> {
                PersonalCardInfoFragment.newInstance()
            }
            else -> Fragment()
        }
        fragment.arguments = intent.extras
        supportFragmentManager.beginTransaction()
            .add(R.id.container, fragment, fragment.javaClass.simpleName)
            .commitAllowingStateLoss()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        fragment.onActivityResult(requestCode, resultCode,data)
    }
}